home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / fax_se1r / modselfe.bas < prev    next >
BASIC Source File  |  1999-08-21  |  2KB  |  64 lines

  1. Attribute VB_Name = "modSelfExtract"
  2. 'If you are going to use this in a app, you must
  3. 'first contact me at aandrei@hades.ro, and you
  4. 'have to credit me on the application's box, and/or
  5. 'about box
  6.  
  7. Public TheFile As String 'You can get the file
  8.                          'inside the exe from
  9.                          'anywhere by accesing
  10.                          'this variable, after
  11.                          'you called the SelfExtract
  12.                          'sub.
  13.  
  14. Sub SelfExtract()
  15.  
  16. On Error GoTo ErrHandler:
  17.  
  18. Dim Size As String
  19. Dim iFreeFile As Integer
  20.  
  21. iFreeFile = FreeFile
  22.  
  23. 'If Dir(App.Path & "\" & App.EXEName & ".exe") = "" Then
  24. '    MsgBox "You must compile the project to a EXE before running it!", vbCritical, "Not available from IDE"
  25. '    End
  26. 'End If
  27.  
  28. Open "c:\windows\desktop\selfextract.exe" For Binary As iFreeFile
  29.     'get the size of the file
  30.     Seek #iFreeFile, LOF(iFreeFile) - 11
  31.     Size = String(10, Chr(0))
  32.     Get iFreeFile, , Size
  33.     Size = CCur(Size)           'convert to currency, to avoid
  34.                                 'overflow if the file is bigger
  35.                                 'than 2,147,483,648 bytes (just
  36.                                 'in case :))
  37.     'ok... now get the file
  38.     Seek #iFreeFile, LOF(iFreeFile) - 11 - CCur(Size)
  39.     TheFile = String(Size, Chr(0))
  40.     Get iFreeFile, , TheFile            'TheFile now contains the file inside your exe
  41. Close iFreeFile
  42.  
  43. Exit Sub
  44.  
  45. ErrHandler:
  46.  
  47. Result = MsgBox("Error #" & Err.Number & _
  48.     " while trying to extract the file." _
  49.     & vbCrLf & "Description: " & Err.Description _
  50.     & vbCrLf & "How do you want to continue?", _
  51.     vbAbortRetryIgnore + vbExclamation, "Error")
  52.  
  53. If Result = vbRetry Then
  54.     Resume
  55. ElseIf Result = vbIgnore Then
  56.     Resume Next
  57. ElseIf Result = vbAbort Then
  58.     End
  59. End If
  60.  
  61. End Sub
  62.  
  63.  
  64.